import 'package:boss/models/commodity.dart';
import 'package:boss/ui/widget/custom_list_title.dart';
import 'package:boss/ui/widget/image/base_image.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';

class OfferCommodityItem extends StatelessWidget {
  final Commodity data;
  final VoidCallback onDeleted;

  const OfferCommodityItem({
    Key key,
    @required this.data,
    this.onDeleted,
  }) : super(key: key);

  int get price => data.commoditySkuList.length > 0 ? data.commoditySkuList[0].skuPrice : data.price;

  String get title => '${data.title}${data.sku != null ? '（${data.sku.skuName}）' : ''}    ¥${AmountUtil.price2String(price)}/${data.unit}';

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.symmetric(
        horizontal: 25.w,
      ),
      child: CustomListTitle(
        title: title,
        trailing: GestureDetector(
          onTap: onDeleted,
          child: BaseImage(
            'assets/image/delete_icon.png',
            width: 44.w,
            height: 44.w,
          ),
        ),
      ),
    );
  }
}
